from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class PostBase(BaseModel):
    """帖子基础模型"""
    title: str = Field(..., description="帖子标题")
    content: str = Field(..., description="帖子正文")
    images: Optional[List[str]] = Field(None, description="图片URL列表")
    tags: Optional[str] = Field(None, description="标签，以逗号分隔")


class PostCreate(PostBase):
    """创建帖子请求模型"""
    author_id: Optional[int] = Field(None, description="创建者ID")


class PostUpdate(BaseModel):
    """更新帖子请求模型"""
    title: Optional[str] = Field(None, description="帖子标题")
    content: Optional[str] = Field(None, description="帖子正文")
    images: Optional[List[str]] = Field(None, description="图片URL列表")
    tags: Optional[str] = Field(None, description="标签，以逗号分隔")
    status: Optional[int] = Field(None, description="状态")
    error_message: Optional[str] = Field(None, description="错误信息")


class PostResponse(PostBase):
    """帖子响应模型"""
    id: int
    status: int = Field(..., description="状态: 0-草稿, 1-待发布, 2-已发布, 3-发布失败")
    author_id: Optional[int]
    error_message: Optional[str]
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True


class PublishJobBase(BaseModel):
    """发布任务基础模型"""
    job_cron: str = Field(..., description="CRON表达式")
    job_desc: str = Field(..., description="任务描述")


class PublishJobCreate(PublishJobBase):
    """创建发布任务请求模型"""
    post_id: int = Field(..., description="关联的帖子ID")


class PublishJobResponse(PublishJobBase):
    """发布任务响应模型"""
    id: int
    post_id: int
    xxl_job_id: Optional[int]
    status: int = Field(..., description="任务状态: 0-待启动, 1-运行中, 2-已停止, 3-已完成")
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True


class AIGenerateRequest(BaseModel):
    """AI生成内容请求模型"""
    topic: str = Field(..., description="主题")
    style: str = Field("小红书爆款", description="风格")


class AIGenerateResponse(BaseModel):
    """AI生成内容响应模型"""
    title: str
    content: str
    suggested_tags: Optional[str] = None